home *** CD-ROM | disk | FTP | other *** search
- # Print Fibonacci numbers
- cmode
- proc fib(x) { # This x is a prototype
- # a, b, c will all be defined as global variables
- a = 0
- b = 1
- while (b < x) {
- print b, "\n"
- c = b
- b += a
- a = c
- }
- }
-
- proc fib2(x) {
- auto a,b,c # These a,b,c are local and hide global a,b,c above
-
- for(a=0,b=1;b<x;c=b,b+=a,a=c) {
- b # This is equivalent to (print b, "\n")
- }
- }
-
- i=1
- while (i++<10) {
- fib(1000)
- }
- i=1
- while (i++<10) {
- fib2(1000)
- }
- fmode
-